//
//  DemoCController.swift
//  SwiftBindDemo
//
//  Created by 万孟超 on 2023/12/27.
//

import UIKit
import CSBind

class DemoCController: UIViewController {

    @IBOutlet weak var tf2: UITextField!
    @IBOutlet weak var tf1: UITextField!
    
    var bindDispose: CSBindDispose?
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    @IBAction func dbind(_ sender: Any) {
        bindDispose = (tf2, \.text) <==> (tf1, \.text)
        bindDispose?.isIgnoreSameValue = true
        Alert.show("开启双向绑定，tf2的值和tf1的值相互改变", on: self)
    }
    
    @IBAction func bind(_ sender: Any) {
        bindDispose = (tf1, \.text) ==> (tf2, \.text)
        Alert.show("开启单向绑定，tf2的值会随着tf1的值改变而改变", on: self)
    }
    @IBAction func pause(_ sender: Any) {
        bindDispose?.pause()
    }
    @IBAction func restart(_ sender: Any) {
        bindDispose?.run()
    }
    @IBAction func free(_ sender: Any) {
        bindDispose?.free()
    }
}
